home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / WindowContentView.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  5.0 KB  |  169 lines  |  [TEXT/CWIE]

  1. // WindowContentView.java
  2. // By Ned Etcode
  3. // Copyright 1995, 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9. /** View subclass used by an InternalWindow to hold its contents.<p>
  10.   * @note 1.0 added accessor for color attribute
  11.   */
  12. public class WindowContentView extends View {
  13.     Color       _color;
  14.     boolean     transparent = false;
  15.  
  16.     static final String         COLOR_KEY = "color";
  17.     static final String         TRANSPARENT_KEY = "transparent";
  18.  
  19.  
  20.     /* constructors */
  21.  
  22.     /** Constructs a WindowContentView with origin (0, 0) and zero width and
  23.       * height.
  24.       */
  25.     public WindowContentView() {
  26.         this(0, 0, 0, 0);
  27.     }
  28.  
  29.     /** Convenience constructor for instantiating a WindowContentView with
  30.       * bounds <B>rect</B>.
  31.       */
  32.     public WindowContentView(Rect rect) {
  33.         this(rect.x, rect.y, rect.width, rect.height);
  34.     }
  35.  
  36.     /** Convenience constructor for instantiating a WindowContentView with
  37.       * bounds (<B>x</B>, <B>y</B>, <B>width</B>, <B>height</B>).
  38.       */
  39.     public WindowContentView(int x, int y, int width, int height) {
  40.         super(x, y, width, height);
  41.  
  42.         _color = Color.lightGray;
  43.     }
  44.  
  45.     /** Sets the background color displayed by the WindowContentView.  By
  46.       * default, this color is Color.lightGray.
  47.       * This is IFC 1.0 API that has been replaced by setBackgroundColor()
  48.       * @see #setBackgroundColor
  49.       */
  50.     public void setColor(Color aColor) {
  51.         setBackgroundColor(aColor);
  52.     }
  53.  
  54.     /** Sets the background color displayed by the WindowContentView.  By
  55.       * default, this color is Color.lightGray.
  56.       *
  57.       */
  58.     public void setBackgroundColor(Color aColor) {
  59.         _color = aColor;
  60.     }
  61.  
  62.     /** Returns the background color displayed by the WindowContentView.
  63.       *
  64.       */
  65.     public Color backgroundColor() {
  66.         return _color;
  67.     }
  68.  
  69.     /** Sets the WindowContentView to be transparent or opaque.
  70.       */
  71.     public void setTransparent(boolean flag) {
  72.         transparent = flag;
  73.     }
  74.  
  75.     /** Overridden to return <b>true</b> if the WindowContentView is
  76.       * transparent.
  77.       * @see #setTransparent
  78.       */
  79.     public boolean isTransparent() {
  80.         return transparent;
  81.     }
  82.  
  83.     /** Fills the WindowContentView with its color, unless it or its
  84.       * InternalWindow is transparent.
  85.       */
  86.     public void drawView(Graphics g) {
  87.         InternalWindow  theWindow;
  88.         View            nextView;
  89.         Rect            nextRect, myBounds;
  90.         Vector          tmpVector;
  91.         int             i, j;
  92.  
  93.         theWindow = window();
  94.         if (_color == null || isTransparent() || theWindow.isTransparent()) {
  95.             return;
  96.         }
  97.  
  98.         g.setColor(_color);
  99.  
  100.         i = subviewCount();
  101.  
  102.         /* DMM - ALERT! - This isn't really what you want.  It's trying to
  103.             avoid filling the rectangle for a non-transparent window that
  104.             is obscured by subviews.  But it doesn't check for the
  105.             opacity of the subviews.  It's cheaper anyway to just fill
  106.             the whole window, than several smaller parts.  So I'm forcing it
  107.             to always draw the background color.  The transparent case is
  108.             caught above
  109.         if (i == 0) {
  110.             g.fillRect(0, 0, width(), height());
  111.         } else {
  112.             myBounds = Rect.newRect(0, 0, width(), height());
  113.  
  114.             while (i-- > 0) {
  115.                 nextView = (View)_subviews.elementAt(i);
  116.                 tmpVector = VectorCache.newVector();
  117.                 myBounds.computeDisunionRects(nextView.bounds, tmpVector);
  118.                 if (tmpVector != null) {
  119.                     j = tmpVector.count();
  120.                     while (j-- > 0) {
  121.                         nextRect = (Rect)tmpVector.elementAt(j);
  122.                         g.fillRect(nextRect);
  123.                     }
  124.                 }
  125.  
  126.                 Vector.returnVector(tmpVector);
  127.             }
  128.  
  129.             Rect.returnRect(myBounds);
  130.         }
  131.         */
  132.  
  133.         g.fillRect(0, 0, width(), height());
  134.     }
  135.  
  136. /* archiving */
  137.  
  138.     /** Describes the WindowContentView class' coding information.
  139.       * @see Codable#describeClassInfo
  140.       */
  141.     public void describeClassInfo(ClassInfo info) {
  142.         super.describeClassInfo(info);
  143.  
  144.         info.addClass("netscape.application.WindowContentView", 1);
  145.         info.addField(COLOR_KEY, OBJECT_TYPE);
  146.         info.addField(TRANSPARENT_KEY, BOOLEAN_TYPE);
  147.     }
  148.  
  149.     /** Encodes the WindowContentView.
  150.       * @see Codable#encode
  151.       */
  152.     public void encode(Encoder encoder) throws CodingException {
  153.         super.encode(encoder);
  154.  
  155.         encoder.encodeObject(COLOR_KEY, _color);
  156.         encoder.encodeBoolean(TRANSPARENT_KEY, transparent);
  157.     }
  158.  
  159.     /** Decodes the WindowContentView.
  160.       * @see Codable#decode
  161.       */
  162.     public void decode(Decoder decoder) throws CodingException {
  163.         super.decode(decoder);
  164.  
  165.         _color = (Color)decoder.decodeObject(COLOR_KEY);
  166.         transparent = decoder.decodeBoolean(TRANSPARENT_KEY);
  167.     }
  168. }
  169.